﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tomahawk.Runtime;
using Tomahawk.Runtime.Logic;
using Microsoft.Xna.Framework;
using Tomahawk.Runtime.Components;
using Tomahawk.Runtime.Rendering.Materials;
using Tomahawk.Runtime.Rendering;

namespace Initialization.GameStates
{
    public class ParticlesActor : XActor
    {
        float time = 0.0f;

        public ParticlesActor()
        {
            UpdateRequired = true;
        }

        protected override void OnPostBeginPlay()
        {
        }

        protected override void OnUpdate(float elapsedTime)
        {
            time += elapsedTime;

            //Vector3 position = Vector3.Zero;
            //position.Z = 200.0f * (float)Math.Sin(time);
            //this.SetLocation(ref position);

            base.OnUpdate(elapsedTime);
        }
    }

    public class TeapotActor : XActor
    {
        public TeapotActor()
        {
        }
    }

    class BasicGameState : GameState
    {
        public ParticlesActor particles = null;
        public TeapotActor teapot = null;

        protected override void OnLoad()
        {
            particles = (ParticlesActor)XWorld.Instance.CreateObject(typeof(ParticlesActor), "", @"Examples.Particles.Content\particlesactor.xml");
            teapot = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "", @"Examples.Particles.Content\teapotactor.xml");
            Engine.Instance.ResourceManager.LoadPendantResources(this.ContentManager);

            SASMaterial material = Engine.Instance.MaterialManager.Load<SASEffect>(@"Tomahawk.Content\Materials\generics@standard_Material", this.ContentManager);
            SASEffect effect = material.Effect;

            if (effect != null)
            {
                bool enable = true;
                bool disable = false;

                effect.Parameters["EnableDiffuseMap"].SetBoolValue(ref enable);
                effect.Parameters["EnableNormalMap"].SetBoolValue(ref enable);
                effect.Parameters["EnableEnvironmentMap"].SetBoolValue(ref disable);
                effect.Parameters["EnableLight0"].SetBoolValue(ref disable);
                effect.Parameters["EnableLight1"].SetBoolValue(ref disable);
            }
        }

        protected override void OnUnload()
        {
        }

        protected override void OnInitialize()
        {
            Engine.Instance.CameraManager.SetActiveCamera(FreeCamComponent.label);
            Tomahawk.Runtime.Rendering.Camera camera = Engine.Instance.CameraManager.ActiveCamera;
            camera.LookAt(
                new Vector3(-10, 0, 0),
                new Vector3(0, 0, 0),
                Vector3.UnitY);
        }

        protected override void OnDestroy()
        {
        }
    }
}
